package nongchang.kuaijiecaifu.com.ncapp_android.ui;

import android.app.Activity;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ezy.widget.view.AutofitImageView;
import nongchang.kuaijiecaifu.com.ncapp_android.Kuaijie;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.activity.BaseActivity;
import nongchang.kuaijiecaifu.com.ncapp_android.retrofit.API;
import nongchang.kuaijiecaifu.com.ncapp_android.util.MathUtil;

public class AccountRegisterActivity extends BaseActivity {
    @BindView(R.id.orderby)
    TabLayout mTabOrderBy;
    @BindView(R.id.img_shouji)
    AutofitImageView imgShouji;
    @BindView(R.id.img_shouji_2)
    AutofitImageView imgShouji2;
    @BindView(R.id.txt_phone)
    EditText txtPhone;
    @BindView(R.id.txt_phone_number)
    EditText txtPhoneNumber;
    @BindView(R.id.txt_password)
    EditText txtPassword;
    @BindView(R.id.txt_repassword)
    EditText txtRepassword;
    @BindView(R.id.txt_yanzheng_number)
    EditText txtYanzhengNumber;
    @BindView(R.id.img_yanzheng)
    AutofitImageView imgYanzheng;
    @BindView(R.id.btn_accepted)
    CheckBox btnAccepted;
    @BindView(R.id.btn_register)
    Button btnRegister;
    @BindView(R.id.btn_protocol)
    TextView btnKuaijieTxt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_register);
        setupToolbarWithHome(R.id.toolbar);
        ButterKnife.bind(this);
        btnKuaijieTxt.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        Drawable drawable=this.getResources().getDrawable(R.drawable.checkbox_select);
        drawable.setBounds(1,0,50,50);
        btnAccepted.setCompoundDrawables(drawable,null,null,null);

        mTabOrderBy.addTab(mTabOrderBy.newTab().setText("手机注册"), true);
        mTabOrderBy.addTab(mTabOrderBy.newTab().setText("邮箱注册"));
        mTabOrderBy.setOnTabSelectedListener(onTabSelectedListener);
        ViewGroup root= (ViewGroup) getRootView(this);
//        changeFonts(root,this);
        Glide.with(this).load("http://www.kjwangluo.com/App/Verify/index.html").skipMemoryCache( true ).diskCacheStrategy( DiskCacheStrategy.NONE ) .placeholder(R.drawable.bg_ract_greye5).centerCrop().into(imgYanzheng);
        imgYanzheng.setOnClickListener(view->{

            Glide.with(this).load("http://www.kjwangluo.com/App/Verify/index.html").skipMemoryCache( true ).diskCacheStrategy( DiskCacheStrategy.NONE ) .centerCrop().placeholder(R.drawable.bg_ract_greye5).into(imgYanzheng);
        });
    }

    TabLayout.OnTabSelectedListener onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            if (tab.getPosition() == 1) {
                imgShouji.setImageResource(R.mipmap.iconfont_youxiang);
                imgShouji2.setImageResource(R.mipmap.iconfont_youjiandakai);
                txtPhone.setHint("邮箱号码");
                txtPhoneNumber.setHint("邮箱验证码");
            } else {
                imgShouji.setImageResource(R.mipmap.shouji4);
                imgShouji2.setImageResource(R.mipmap.shouji3);
                txtPhone.setHint("11位手机号码");
                txtPhoneNumber.setHint("手机验证码");
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    };

    private static View getRootView(Activity context) {
        return ((ViewGroup) context.findViewById(android.R.id.content)).getChildAt(0);
    }

//    public void changeFonts(ViewGroup root, Activity act) {
//        for (int i = 0; i < root.getChildCount(); i++) {
//            View v = root.getChildAt(i);
//            if (v instanceof TextView) {
//                ((TextView) v).setTypeface(Kuaijie.iconFont);
//            } else if (v instanceof Button) {
//                ((Button) v).setTypeface(Kuaijie.iconFont);
//            } else if (v instanceof EditText) {
//                ((EditText) v).setTypeface(Kuaijie.iconFont);
//            }else if(v instanceof CheckBox){
//                ((CheckBox) v).setTypeface(Kuaijie.iconFont);
//            }
//            else if (v instanceof ViewGroup) {
//                changeFonts((ViewGroup) v, act);
//            }
//        }
//    }

    @OnClick({R.id.btn_protocol})
    void OnClick(View view) {
        switch (view.getId()) {
            case R.id.btn_protocol:
                WebViewActivity.start(this,"快捷财富协议", API.URI_REGISTER_PROTOCOL);
                break;
        }
    }
}
